package com.redpack.redpost.util.Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.redpack.redpost.util.dao.*;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class DelPaqueteArribo
 */
public class DelPaqueteArribo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DelPaqueteArribo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
				String respuesta = "";
				String cve_pieza = "";
				String cve_arribo = "";
				
				cve_pieza = request.getParameter("cve_pieza");
				cve_arribo = request.getParameter("cve_arribo");
			
				
				try 
				{
			        if(cve_arribo != "" && cve_pieza != "")
			  	  	{
			        	if(isNumeric(cve_arribo) && isNumeric(cve_pieza)){
			        		
			        		MultipiezaArriboDao.delPaqueteArribo(Integer.parseInt(cve_pieza),Integer.parseInt(cve_arribo));
			        	}
			        	else{
			        		respuesta = "No se logoro realizar la accion.";
			        	}
			  	  	}
				} 
				catch (Exception ex) 
				{
		         ex.printStackTrace();
		         response.getWriter().write(ex.toString());  
		         respuesta = ex.toString();
		         //System.out.println(ex);
		     }
		        response.getWriter().write(respuesta);  
			}
	
	private static boolean isNumeric(String cadena){
	    try 
	    {
		    Integer.parseInt(cadena);
		    return true;
	    } 
	    catch (NumberFormatException nfe){
	    	return false;
	    }
	    
	}
	

}
